﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ADEVSO.Data;
using SmartParking.Bussiness;
using System.Configuration.Provider;

namespace SmartParking.Web.Manager
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                (Master as ManagerTemplate).Title = "Login";
                Bussiness.SecurityManager.RefreshRoles(Profile.ManagerID, Request.UserHostAddress);
            }
        }    

        protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
        {
            try
            {
                SmartParking.Data.Entities.Manager manager = null;
                if (SecurityManager.Login(Session, Login1.UserName, Login1.Password, Request.UserHostAddress, out manager))
                {
                    ProfileCommon profile = ProfileCommon.Create(manager.UserName, true) as ProfileCommon;
                    profile.ManagerID = manager.ManagerID;
                    profile.CustomerID = manager.CustomerID;
                    profile.UserRole = manager.Role.Name;
                    profile.Save();

                    manager.RefreshUserRoles();

                    e.Authenticated = true;
                }
            }
            catch
            {
            }
        }
    }
}
